home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tptsr.zip / CMDLN.DEM < prev    next >
Text File  |  1990-06-04  |  3KB  |  99 lines

  1. {
  2.     cmdln.dem
  3.     6-4-90
  4.     Demo the use of cmdln.pas
  5.  
  6.     Copyright 1990
  7.     John W. Small
  8.     All rights reserved
  9.  
  10.     PSW / Power SoftWare
  11.     P.O. Box 10072
  12.     McLean, Virginia 22102 8072
  13.     (703) 759-3838
  14. }
  15.  
  16. program cmdlnDemo;
  17. uses crt, cmdln;
  18. var options : string;
  19.     params : CmdLnParams;
  20.     i : integer;
  21. begin
  22.     clrscr;
  23.     if ParamCount > 0 then begin
  24.         writeln('Test the CmdLnParam object with the following command line:');
  25.         writeln;
  26.         write('  ');
  27.         for i := 0 to ParamCount do
  28.             write(ParamStr(i),' ');
  29.         writeln
  30.         end;
  31.     params.init('o:');
  32.     if boolean(params.getOption) then;
  33.     if (params.optCh <> 'o') or (length(params.optArg) = 0)
  34.         then begin
  35.         writeln('usage: cmdln -ooptions *');
  36.         writeln;
  37.         writeln('where "options" consists of the letters to look for, and');
  38.         writeln('      "*" are the command line arguments to be parsed by "options."');
  39.         writeln('      For the purposes of this test "o" switches are skipped.');
  40.         writeln;
  41.         writeln('For example, with the command line: ');
  42.         writeln;
  43.         writeln('    cmdln /oC:af:z /afnew /zC cmdfile outfile');
  44.         writeln;
  45.         writeln('the "options" string is "C:af:z", which means that this particular invocation');
  46.         writeln('of the demo will recognize "C", "a", "f" and "z" as switch options.  "C" and');
  47.         writeln('"f" take arguments, which is indicated by the colon after each in the "options"');
  48.         writeln('string.  Switch options are introduced by "/" or "-" in DOS.  The "options"');
  49.         writeln('string is then used to parse the rest of the command line.  In this case it');
  50.         writeln('recognizes "a", "f" with argument "new", "z", and "C" with argument "cmdfile."');
  51.         writeln('Notice that options taking arguments must appear last in the switch clusters.');
  52.         writeln('Run this demo with command lines similar to this example to see how it');
  53.         writeln('works.  Then besure to read the notes in the interface section of cmdln.pas');
  54.         writeln('for complete instructions on how to use the CmdLnParams object.  Then return');
  55.         writeln('to the source code of this demo and study how I used it.  You will then be');
  56.         writeln('ready start coding with the CmdLnParams object.');
  57.         writeln;
  58.         writeln('Press "Enter" to quit.');
  59.         readln;
  60.         halt
  61.         end;
  62.     writeln;
  63.     writeln('Parse for the following options: ');
  64.     writeln;
  65.     for i := 1 to length(params.optArg) do begin
  66.         write('      ',params.optArg[i]);
  67.         if i < length(params.optArg) then
  68.             if params.optArg[i+1] = ':' then begin
  69.                 inc(i);
  70.                 write('   with argument')
  71.                 end;
  72.         writeln
  73.         end;
  74.     writeln;
  75.     writeln('Parameters parsed as ...');
  76.     writeln;
  77.     params.init(params.optArg);
  78.     while (params.getOption <> #0) do
  79.         if params.optCh = '?' then
  80.             if params.optNot = 'o' then
  81.                 params.nextCluster
  82.             else
  83.                 write(' optNot:  ',params.optNot)
  84.         else if length(params.optArg) > 0 then
  85.             writeln('  optCh:  ',params.optCh,'     optArg:  ',params.optArg)
  86.         else
  87.             writeln('  optCh:  ',params.optCh);
  88.     while (params.paramNo <= ParamCount) do begin
  89.         writeln('ParamNo:  ',params.paramNo,
  90.             '   ParamStr:  ',ParamStr(params.paramNo));
  91.         inc(params.paramNo)
  92.         end;
  93.     writeln;
  94.     write('Press "Enter" to quit.');
  95.     readln
  96. end.
  97.  
  98.  
  99.